package com.wondersgroup.fjzlpt.tbxt.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.remoteResult.ResultObject;
import com.wondersgroup.fjzlpt.tbxt.dao.inter.gyzjb.ShjlDao;
import com.wondersgroup.fjzlpt.tbxt.dao.inter.wsj.WsjDao;
import com.wondersgroup.fjzlpt.tbxt.service.inter.wsj.WsjService;
import com.wondersgroup.fjzlpt.tbxt.util.ControllerUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by sanma on 2017/7/18.
 */
@Service
public class WsjServiceImpl implements WsjService {

    @Autowired
    private WsjDao wsjDao;
    @Autowired
    private ShjlDao shjlDao;
    
    
    
    @Override
    public JSONObject queryNbByPage(Map<String, String> map) {
        ControllerUtils.pageFormat(map);
        return wsjDao.queryNBPageAll(map);
    }

    @Override
    public JSONObject queryYbByPage(Map<String, String> map) {
		ControllerUtils.pageFormat(map);
        return wsjDao.queryYBPageAll(map);
    }

    /**
     * 审核报表
     * @param map
     * @return
     */
    @Override
    public JSONObject checkBb(Map<String,String> map ){
    	ResultObject ro = new ResultObject();
    	try {
    		//更新报表状态
    		Map<String,String> upMap = new HashMap<String, String>();
    		upMap.put("tableName", map.remove("tableName"));
    		upMap.put("ZT", map.get("ZT"));
    		upMap.put("ID", map.get("ID"));
    		wsjDao.updateBbZtByTableName(upMap);
    		//插入审核表数据
    		shjlDao.insert(map);
		} catch (Exception e) {
			ro.changeFaultState("报表审核失败，请稍后再试！");
			throw new RuntimeException("报表审核失败!");
		}
    	return (JSONObject)JSON.toJSON(ro);
    }

    /**
     * 分页查询报表审核记录
     * @param map
     * @return
     */
	@Override
	public JSONObject queryShjlByPage(Map<String, String> map) {
		ControllerUtils.pageFormat(map);
		return shjlDao.queryShjlByPage(map);
	}
}
